#include "MineDesign3D/Light.hpp"
#include <Windows.h>
#include <GL/GL.h>
#include "MineDesign3D/UIManager.hpp"
#include "MineDesign3D/ViewManager.hpp"
namespace MineDesign3D{
void ApplyLight()
{
	const UIData& uiData = g_pUIManager()->GetUIData();

	if(!uiData.LightEnable)
		return;

	glPushAttrib(GL_LIGHTING_BIT);

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);

	vector3 dir = g_pViewManager()->getLookAt() - g_pViewManager()->getEyePos();
	dir.normalize();

	float LightPos[4];
	for(int i = 0 ; i < 3 ; ++i)
		LightPos[i] = -dir[i];
	LightPos[3] = 0;

	const float lightDiffuse[3] = {1.0f, 1.0f, 1.0f};
	const float lightAmbient[3] = {0.45f, 0.45f, 0.45f};
	const float lightSpecular[3] = {1.0f, 1.0f, 1.0f};

	glLightfv(GL_LIGHT0, GL_POSITION, LightPos);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
	glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
	glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular);
}
void DisApplyLight()
{
	const UIData& uiData = g_pUIManager()->GetUIData();

	if(!uiData.LightEnable)
		return;
	glPopAttrib();
}
}//MineDesign3D